<template>
  <div class="app-action" style="background: #f2f2f2">
    <div>
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="off" label-position="left">
        <!--<img src="../../assets/loginbg.png" alt="" style="width: 100%;height: 100%;position: absolute;left: 0;top: 0;z-index: 0">-->
        <div class="tologin">
          <span>账号登录</span>
        </div>
        <div style="position: relative">
          <el-form-item prop="userName">
            <span class="svg-container svg-container_login">
              <img src="../../assets/username_icon.png" alt="">
            </span>
            <el-input v-model="loginForm.userName" name="username" type="text" auto-complete="off" placeholder="请输入用户名/手机号" />
          </el-form-item>

          <el-form-item prop="password">
            <span class="svg-container">
              <img src="../../assets/password_icon.png" alt="">
            </span>
            <el-input v-model="loginForm.password" type="password" name="password" auto-complete="off" placeholder="请输入密码" @keyup.enter.native="handleLogin" />
          </el-form-item>
          <div style="padding-top: 20px">
            <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;background-color:#5AA4E9;height: 44px;line-height: 25px;font-size: 18px " @click.native.prevent="handleLogin">登录</el-button>
          </div>
          <div>
            <span v-if="success" id="success">登录成功!</span>
            <!--<span v-if="errors" id="errors">{{ error }}!</span>-->
          </div>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import { doGet } from '@/api/index'

export default {
  data() {
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('密码长度应大于6'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        userName: '',
        password: ''
      },
      loginRules: {
        userName: [{ required: true, message: '账户不允许为空', trigger: 'blur' }],
        password: [
          { required: true, message: '密码不允许为空', trigger: 'blur' },
          { validator: validatePassword, trigger: 'blur' }
        ]
      },
      loading: false,
      success: false,
      errors: false,
      error: undefined
    }
  },
  created() {
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid && !this.loading) {
          this.loading = true
          doGet('apilogin.html?op=login', this.loginForm).then((response) => {
            this.loading = false
            this.success = true
            this.errors = false
            this.$router.push({ path: '../company/compandsigning' })
          }).catch(response => {
            this.errors = true
            this.success = false
            this.loading = false
            // this.error = response.message
            this.$notify.error({
              title: '失败',
              message: response.message
            })
          })
        } else {
          return false
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
  #success {
    color: #13ce66
  }
  #errors {
    color: #C03639
  }
  .app-action {
    background: #fff;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    /*position: relative;*/
    .el-form {
      width: 370px;
      background: #fff;
      padding: 20px;
      /*position: absolute;*/
      /*top: 25%;*/
      /*left: 40%;*/
      margin: 0 auto;
      /deep/ .el-form-item__content {
        position: relative;
      }
      .el-input {
        display: inline-block;
        height: 47px;
        width: 85%;
        border: 0;
      }
    }
    .tologin {
      font-size: 16px;
      font-family: Microsoft Yahei;
      font-weight: 700;
      line-height: 16px;
      text-align: center;
      padding-bottom: 35px;
      .svg-container {
        padding: 6px 5px 6px 15px;
        color: #889aa4;
        vertical-align: middle;
        width: 30px;
        display: inline-block;
      }
    }
  }
</style>
